#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

void Swap(int* p1, int* p2)
{
	int tem = *p1;
	*p1 = *p2;
	*p2 = tem;
}


void PrinfArray(int* a, int n)
{
	int i = 0;
	for (i = 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}

int _QuickSort(int* a, int left, int right)
{
	int prev = left;
	int cur = prev + 1;
	int keyi = left;
	while (cur <= right)
	{
		if (a[cur] < a[keyi] && prev++ != cur)
		{
			Swap(&a[cur], &a[prev]);
		}
		cur++;
	}
	Swap(&a[prev], &a[keyi]);
	keyi = prev;
	return keyi;
}

void QuickSort(int* a, int begin, int end)
{
	if (begin >= end)
		return;
	//[begin, keyi - 1] keyi [keyi + 1,end]
	int keyi = _QuickSort(a, begin, end);
	QuickSort(a, begin, keyi - 1);
	QuickSort(a, keyi + 1, end);
	
}

int main()
{
	int a[10] = { 9,8,7,6,5,4,3,2,1,0 };
	int len = sizeof(a) / sizeof(int);
	PrinfArray(a, len);
	QuickSort(a, 0, len - 1);
	PrinfArray(a, len);
	return 0;
}